
## Replication Data ##
library(tidyverse)

# loading data 
house_data <- read.csv("house_presidential_voteshare_2000-2024.csv")
senate_data <- read.csv("senate_presidential_voteshare_2000-2024.csv")

# House Republicans 
republican_house <- house_data %>% 
  filter(party == "(R)") %>% 
  group_by(congress) %>% 
  summarize(
    mean_presvote = mean(r_presvote, na.rm = TRUE),
    se_presvote = sd(r_presvote, na.rm = TRUE) / sqrt(n()),
    .groups = "drop"
  ) %>%
  mutate(
    lower_ci = mean_presvote - 1.96 * se_presvote,
    upper_ci = mean_presvote + 1.96 * se_presvote
  )

# House Democrats 
democrat_house <- house_data %>% 
  filter(party == "(D)") %>% 
  group_by(congress) %>% 
  summarize(
    mean_presvote = mean(d_presvote, na.rm = TRUE),
    se_presvote = sd(d_presvote, na.rm = TRUE) / sqrt(n()),
    .groups = "drop"
  ) %>%
  mutate(
    lower_ci = mean_presvote - 1.96 * se_presvote,
    upper_ci = mean_presvote + 1.96 * se_presvote
  )

# Senate Republicans
republican_senate <- senate_data %>% 
  filter(republican == 1) %>% 
  group_by(congress) %>% 
  summarize(
    mean_presvote = mean(r_presvote, na.rm = TRUE),
    se_presvote = sd(r_presvote, na.rm = TRUE) / sqrt(n()),
    .groups = "drop"
  ) %>%
  mutate(
    lower_ci = mean_presvote - 1.96 * se_presvote,
    upper_ci = mean_presvote + 1.96 * se_presvote
  )

# Senate Democrats
democrat_senate <- senate_data %>% 
  filter(republican == 0) %>% 
  group_by(congress) %>% 
  summarize(
    mean_presvote = mean(d_presvote, na.rm = TRUE),
    se_presvote = sd(d_presvote, na.rm = TRUE) / sqrt(n()),
    .groups = "drop"
  ) %>%
  mutate(
    lower_ci = mean_presvote - 1.96 * se_presvote,
    upper_ci = mean_presvote + 1.96 * se_presvote
  )


